# Pequena MPI:     module load openmpi/1.6.3/intel/11.1 fftw/3.3.3/openmpi/1.6.3/intel/11.1 
# Pequena serial:  module load compiler/intel11.1 fftw/3.3.3/openmpi/1.6.3/intel/11.1  



# Name of the executable
BGK     = bgk.x
VMD     = vmd.x
NLVP    = nlvp.x

DIMENSIONS = dimensions.o 
MPIMOD     =  mpi_fake.o

MODULES = parameters.o $(MPIMOD) \
          fftw_wrap.o fft_3d.o efield.o evolve.o advect.o collisions.o

F_BGK   = set_space_vectors.o  read_input.o  diagnostics.o  set_ic.o  io.o  filters.o\
          bgk.o

F_VMD   = set_space_vectors.o  read_input.o  diagnostics.o  set_ic.o  io.o  filters.o\
          bgk_utils.o  evolve_lin.o  vmd_lin.o

F_NLVP  = set_space_vectors.o read_input.o  diagnostics.o set_ic.o io.o \
          evolve_nlvp.o nlvp.o

DIMS_DEF  =  -Djx_def=1 -Djy_def=1  -Dnpdir_def=$(np) 
DIMS_SET  =  -Djz_def=$(jz) -Djv_def=$(jv) -Djdir_def=$(jdir)


#------------------------------------------------

# Generic flags and compilers 

OMPLIB = -fopenmp
LDFLAGS = $(LIB)
F90 = gfortran
LIB = $(OMPLIB)  -lfftw3_threads -lfftw3 -lm
FCFLAGS = $(OMPLIB) $(OPT)


ifeq ($(HOSTNAME), hooloovoo)
        F90 = gfortran
        #OPT = -fbounds-check
        OPT =  -fdefault-real-8 -fdefault-integer-8 -O3  -I/usr/local/fftw/fftw-3.3.3/include
        LDFLAGS  =  -L/usr/local/fftw/fftw-3.3.3/lib $(LIB) -m64
endif


ifeq ($(HOSTNAME), odin)
        OPT =  -fdefault-real-8 -fdefault-integer-8  -flto -Ofast
endif


ifeq ($(HOSTNAME), anterior.newmexicoconsortium.org)
        OPT = -fdefault-real-8 -fdefault-integer-8 -O2
endif


ifeq ($(HOSTNAME), pequena)
        F90 = ifort  
        OMPLIB = -openmp 
        OPT  = -i8 -r8 -O2 -I/users/system/fftw/3.3.3/openmpi/1.6.3/intel/11.1/include/
endif

ifeq ($(np), 2)
        F90 = mpif90
        MPIMOD = mpi_wrap.o
endif



# -------------------------------------------------------
# compile


%.o: %.f
	$(F90) $(FCFLAGS) -c $<

%.o: %.f90
	$(F90) $(FCFLAGS) -c $<

default:
	@echo "\n   options:   bgk, vmd, nlvp, hostname"
	@echo "   parameters:  jz=32  jv=256  jdir=2  np=1  (example)\n"

dimensions.o: dimensions.F90
	$(F90)  $(FCFLAGS) $(DIMS_DEF) $(DIMS_SET) -c $<


bgk:   $(DIMENSIONS) $(MODULES) $(F_BGK)
	$(F90)  $(DIMENSIONS) $(MODULES) $(F_BGK) -o $(BGK) $(LDFLAGS)

vmd:  $(DIMENSIONS) $(MODULES) $(F_VMD)
	$(F90)  $(DIMENSIONS) $(MODULES) $(F_VMD) -o $(VMD) $(LDFLAGS)

nlvp:  $(DIMENSIONS) $(MODULES) $(F_NLVP)
	$(F90)  $(DIMENSIONS) $(MODULES) $(F_NLVP) -o $(NLVP) $(LDFLAGS)


hostname:
	@echo $(HOSTNAME)

clean:
	rm -f *~ *.o *.mod
